<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of LoginAction
 *
 * @author ASIMO
 */
class LoginAction extends Action{
    public function index() {
        $err = I('err');
        $this->assign('err', $err);
        $this->display();
    }
    
    public function check() {
        import('ORG.Util.Verify');
        if (Verify::isEmpty(I('username'))==false
            || Verify::isEmpty(I('pwd'))==false) {
            echo "para is empty";
            exit;
            $this->redirect("/Prom/Login/index@".  getDomain(), array('err'=>1));
        }
        
        $username = I('username');
        $pwd = I('pwd');
        $resUser = M('muser')->where("name='".$username."'")->find();
        if ($resUser['pwd']==md5($pwd)) {
            setcookie('yjdl',1);
            M('muser')->where('id='.$resUser['id'])->setField('uptime', time());
            $this->redirect('/Prom@'.  getDomain());
        }
        else {
            $this->redirect("/Prom/Login/index@".  getDomain(), array('err'=>2));
        }
    }
    
    public function logout() {
        setcookie('yjdl', NULL);
        $this->redirect("/Prom/Login@".  getDomain());
    }
}
